package com.sendi.system.util.export;

public class IExcelhelper {
	public static String getRCNum(String excelFlag)
	{
		char[] chars = excelFlag.toLowerCase().toCharArray();
		int i = 0;
		for(char c : chars)
		{
			if(c>='a' && c<='z')
				i++;
			else
				break;
		}
		if(i>2 ||(i==2 && chars[0]>'i') || (i==2 && chars[0]=='i' && chars[1]>'v'))
		{
			throw new RuntimeException("列数值超过最大255！");
		}
		return excelFlag.substring(i)+"-"+(int)clac26to10(excelFlag.substring(0,i));
	}
	private static double clac26to10(String str26)
	{
		String baseStr = "abcdefghijklmnopqrstuvwxyz";
		char[] chars = str26.toLowerCase().toCharArray();
		double d = 0;
		int i = 1;
		for(char c : chars)
		{
			int num = baseStr.indexOf(c);
			if(num==-1)
				throw new RuntimeException("包含非法字符:"+c);
			if(num==0&&chars.length>1&&i==1)
				num=1;
			d += Math.pow(26,chars.length-i)*num;
			i++;
		}
		return d;
	}

}
